package com.mm.cloud.common.security.loginuser;

import com.mm.cloud.common.core.constant.CommonConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.io.Serial;
import java.io.Serializable;
import java.util.Set;

/**
 * 登录用户信息
 *
 * @author mr
 * @since 2021-07-10
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "登录用户信息")
public class LoginUser implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "用户ID")
    private Long userId;

    @Schema(description = "用户名")
    private String username;

    @Schema(description = "公司ID")
    private Long companyId;

    @Schema(description = "店铺ID")
    private Long storeId;

    @Schema(description = "权限列表")
    private Set<String> authorities;

    @Schema(description = "角色列表")
    private Set<String> roles;

    @Schema(description = "token")
    private String token;

    /**
     * 判断管理员
     */
    public boolean isAdmin() {
        if (CollectionUtils.isEmpty(this.roles)) {
            return false;
        }
        return roles.contains(CommonConstants.ADMIN);
    }

}
